
	
 <table border="0" width="690">
		 <br/>
		 <tr class="titulo-livro">
			<td>Item</td><td>Remover</td><td>QTD</td><td>Total</td><td>SubTotal</td>
		 </tr>
		 <tr>
			<td colspan="5"><hr><br/></td><td></td><td></td><td></td><td></td>
		 </tr>
 <?php
   $total=0;
   $subtotal=0;
   @session_start();
   include ('conecta.inc');
   if(!isset($_SESSION['carrinho'])){
   
   }else{
   if(count($_SESSION['carrinho'])==0){
     echo "";
   }else{
     foreach($_SESSION['carrinho'] as $id => $qtd){
 
		 
		   $sql=mysql_query("SELECT * FROM livros WHERE '$id' = codigo");
		 	
           while($array=mysql_fetch_array ($sql)) {
		   
           $codigo = $array['codigo'];
		   $nome = $array['titulo'];
		   $valor = $array['preco'];
		   
	
	 
 
?>
		 <tr class="carrinho">
			<td><?php echo $nome ?></td><td><a href="?secao=add_carrinho&acao=del&id=<?php echo $id ?>"><center><img src="imagens/del.png"></center><a/></td>
			<td> <form method="POST" action="?secao=add_carrinho&acao=up"><input type="text" name="prod[<?php echo $id ?>]" size="1" value="<?php echo $qtd ?>"></form></td><td> R$ <?php echo number_format($valor, 2, ',', '.');$valor ?></td>
			<td> R$ <?php $subtotal=($valor*$qtd); echo number_format($subtotal, 2, ',', '.'); $subtotal;  ?></td>
		 </tr>
		 <tr>
			<td colspan="5"><hr><br/></td><td></td><td></td><td></td><td></td>
		 </tr>
	    

 <?php
    
			if(isset($total)){$total+=$subtotal;}else{$total+=$subtotal;} 
			if(!isset($total)){echo"setado";}else{}
			}
		}  
    
     }	
  }
    
?>  

        <tr class="sub-titulo">
			<td><input name="botao" type="submit" hidden value="Atualizar quantidades"></td><td></td><td>Total</td><td> R$ <?php  echo number_format($total, 2, ',', '.'); $total; ?></td>
		 </tr>
		 <br/>
		<tr>
			<td class="carrinho">Calcular frete: <form method="post" action="?secao=add_carrinho&acao=frete"><input type="text" name="cep" size="8" value="" class="form" > 
			<input type="submit" name="calcular" value="Calcular" class="botao-busca"></form></td><td></td><td class="sub-titulo">Frete </td><td class="sub-titulo"> R$  <?php if(isset($_COOKIE['frete'])){echo $_COOKIE['frete'];}else{$_COOKIE['frete']=0;}?></td>
		 </tr>
		 <tr>
			<td><br/><br/><br/></td><td></td><td></td><td></td><td><a href="?secao=pagamento"><img src="imagens/fechar-pedido.png"></a></td>
		</tr>
    </table>	
  
